/** * 옵션미리보기 스크립트, 상품리스트 관련 스크립트 추가함(munhui) * 기존 html/js/product_list.js를 개별디자인3에서 사용하기 위해 jquery화 시킴. * @auther duellist * @date 2011-06-16 **/ var __option_preview_obj = {}; // 옵션 미리보기용 전역변수 function mk_prd_option_preview(uid, e, device) { var link_path = '/shop/'; if (typeof device != "undefined") { link_path = device == 'MOBILE' ? '/m/' : '/shop/'; } if (DESIGN_VIEW == 'RW') { var preview_obj = $(window.event.srcElement); if (preview_obj.hasClass('on')) { $('#MK_opt_preview').html(''); $('img.MS_option_preview').removeClass('on').attr('src', '//skin.makeshop.co.kr/skin/rw_shop/images/icons/btn_opt_view.svg'); return false; } else { $('img.MS_option_preview').removeClass('on').attr('src', '//skin.makeshop.co.kr/skin/rw_shop/images/icons/btn_opt_view.svg'); preview_obj.addClass('on').attr('src', '//skin.makeshop.co.kr/skin/rw_shop/images/icons/btn_opt_view_on.svg'); } } jQuery.ajax({ type: 'POST', url: link_path + 'product_data.ajax.html', dataType: 'html', data: { 'branduid': uid, 'type': 'option' }, success: function(req) { jQuery('#MK_opt_preview').html(req); return false; }, errer: function() { alert('옵션정보 가져오기 실패'); } }); var _evt = e.currentTarget ? e.currentTarget : window.event.srcElement; var offset = ObjectPosition(_evt); __option_preview_obj = _evt; jQuery('#MK_opt_preview').css({ 'visibility': 'visible', 'left': offset[0] + 'px', 'top': offset[1] + 'px' }); // window resize 이벤트 발생시 옵션 미리보기 위치를 다시 잡음 jQuery(window).resize(function() { var _offset = ObjectPosition(__option_preview_obj); jQuery('#MK_opt_preview').css({ 'left': _offset[0] + 'px', 'top': _offset[1] + 'px' }); }); } function ObjectPosition(obj) { var base_rect = document.querySelector('body').getBoundingClientRect(); var target_rect = obj.getBoundingClientRect(); var curleft = target_rect.left - base_rect.left; var curtop = target_rect.top - base_rect.top; // 가운데 정렬때문에 추가함 if (jQuery('#wrap').css('marginLeft') == 'auto') { curleft -= jQuery('#wrap').offset().left; } return [curleft,curtop]; } function mk_prd_benefit(page_type, uid, target, is_mobile) { var url = is_mobile == true ? '/m/product_benefit.html' : '/shop/product_benefit.html'; jQuery.ajax({ type: 'GET', url: url, dataType: 'html', data: { 'uid': uid, 'page_type': page_type, 'target': target, 'rand':Math.random() }, success: function(req) { jQuery('#MS_popup_product_benefit_'+page_type).html(req); jQuery('#MS_popup_product_benefit_'+page_type).show(); return false; }, errer: function() { } }); } // 쿠폰 다운로드 후 최대할인 영역 새로고침처리 function mk_max_benefit() { if ($('#mk_max_benefit_coupon').length > 0 && typeof get_max_benefit_smart_coupon === 'function') { var checked_couponnum_arr = []; var checked_couponnum = ''; // 선택한 쿠폰 ajax 넘겨주기 $('input[name="mk_max_benefit_coupon"]').each(function() { // 선택된 애들만 뽑아서 couponnum에 ,로 구분해주기 if ($(this).is(':checked')) { checked_couponnum_arr.push($(this).attr('couponnum')); } }); if(checked_couponnum_arr.length > 0) { checked_couponnum = checked_couponnum_arr.join(','); } get_max_benefit_smart_coupon(false, checked_couponnum, '', '', ''); } } var mk_coupon_down_ing = false; function mk_prd_benefit_down(page_type, uid, couponnum, is_mobile, provider, sellprice) { var url = is_mobile == true ? '/m/smart_coupon.action.html' : '/shop/smart_coupon.action.html'; if (mk_coupon_down_ing === true) { return false; } if (!page_type || page_type == '') { page_type = 'BENEFIT'; } jQuery.ajax({ type: 'POST', dataType: 'json', url: url, data: { 'action_type' : 'down_coupon', 'down_page' : page_type, 'couponnum': couponnum, 'branduid' : uid, 'provider' : provider, 'sellprice' : sellprice, 'rand':Math.random() }, success: function(req) { if (req.success === true) { mk_prd_benefit(page_type, uid, couponnum, is_mobile); mk_max_benefit(); alert(req.msg); } else { if (req.msg && req.msg.length > 0) { alert(req.msg); } } mk_coupon_down_ing = false; } }); } function mk_prd_benefit_login(is_mobile) { var login_url = is_mobile == true ? '/m/login.html' :'/shop/member.html?type=login'; if (confirm("쿠폰 다운은 로그인 후 가능합니다.\n로그인 하시겠습니까?")) { document.location.href = login_url; } } function mk_prd_benefit_down_fail() { alert('이미 발급받았거나, (선착순) 마감된 쿠폰입니다.'); } var mk_prd_wish_action_lodding = false; function mk_prd_wish_toggle(uid, is_mobile) { if (mk_prd_wish_action_lodding === true) { return; } mk_prd_wish_action_lodding = true; var action_type = 'toggle'; var is_block = false; // block 있을 경우 재확인 함 if ($('.my-wish-list[data-uid='+uid+']').length > 0) { is_block = true; if ($('.my-wish-list[data-uid='+uid+']').hasClass('wish-on') === true) { action_type = 'delete'; } else { action_type = 'insert'; } } var get_prd_count = 'N'; if ($('.my-wish-count[data-uid='+uid+']').length > 0) { get_prd_count = 'Y'; } var _url = is_mobile == true ? '/m/wish.action.html' :'/shop/wish.action.html'; jQuery.ajax({ url : _url, type : 'POST', data: { action_type: action_type, page_type: 'product_list', data_type: 'ones', uid : uid, wish_get_prd_count : get_prd_count }, dataType: 'json', success: function(response) { if (response.is_not_login == true) { mk_prd_wish_login(is_mobile); mk_prd_wish_action_lodding = false; return; } if (response.success == true) { if (is_block === true) { if (response.data.action_type == 'insert') { $('.my-wish-list[data-uid='+uid+']').addClass('wish-on'); if (response.data.pixel_event_id && response.data.pixel_event_id.length > 0) { mk_call_fbq('AddToWishlist', response.data.pixel_event_id) } } else { $('.my-wish-list[data-uid='+uid+']').removeClass('wish-on'); } } if (get_prd_count == 'Y') { $('.my-wish-count[data-uid='+uid+']').html(response.data.prd_count); } if (response.data.is_powerapp && response.data.action_type && response.data.is_powerapp == true && response.data.action_type == 'insert') { response.data.items.forEach(element => { let items = []; items.push(element); let data = { 'type' : 'add_to_wishlist', 'data' : { value: element.sellprice, currency: 'KRW', items: items } } if (typeof appbridgescript === "function") { appbridgescript('galogevent', JSON.stringify(data)); } }); } } else { if (response.message != '') { alert(response.message); } } mk_prd_wish_action_lodding = false; }, error: function(XMLHttpRequest, textStatus, errorThrown) { mk_prd_wish_action_lodding = false; } }); return; } var mk_cate_wish_action_lodding = false; function mk_cate_wish_toggle(code, code_type, is_mobile) { if (mk_cate_wish_action_lodding === true) { return; } mk_cate_wish_action_lodding = true; var action_type = 'toggle'; var is_block = false; // block 있을 경우 재확인 함 if ($('.category-count[data-code='+code+']').length > 0) { is_block = true; if (typeof DESIGN_VIEW != 'undefined' && DESIGN_VIEW == 'RW') { if ($('.category-count[data-code='+code+']').hasClass('count-on')) { action_type = 'delete_cate'; } else { action_type = 'insert_cate'; } } else { var $icon = $('.category-count[data-code='+code+']').find('i.fa'); if ($icon.hasClass('fa-heart')) { action_type = 'delete_cate'; } else { action_type = 'insert_cate'; } } } var get_cate_count = 'N'; if ($('.my-catewish-count[data-code='+code+']').length > 0) { get_cate_count = 'Y'; } var _url = is_mobile == true ? '/m/wish.action.html' :'/shop/wish.action.html'; jQuery.ajax({ url : _url, type : 'POST', data: { action_type: action_type, page_type: 'product_list', data_type: 'ones', ct_code : code, ct_type : code_type, wish_get_cate_count : get_cate_count }, dataType: 'json', success: function(response) { if (response.is_not_login == true) { mk_prd_wish_login(is_mobile); mk_cate_wish_action_lodding = false; return; } if (response.success == true) { if (is_block === true) { if (typeof DESIGN_VIEW != 'undefined' && DESIGN_VIEW == 'RW') { if (response.data.action_type == 'insert_cate') { $('.category-count[data-code='+code+']').addClass('count-on'); } else { $('.category-count[data-code='+code+']').removeClass('count-on'); } } else { var $icon = $('.category-count[data-code='+code+']').find('i.fa'); if (response.data.action_type == 'insert_cate') { $icon.removeClass('fa-heart-o').addClass('fa-heart'); } else { $icon.removeClass('fa-heart').addClass('fa-heart-o'); } } } if (get_cate_count == 'Y') { $('.my-catewish-count[data-code='+code+']').html(response.data.cate_count); } } else { if (response.message != '') { alert(response.message); } } mk_cate_wish_action_lodding = false; }, error: function(XMLHttpRequest, textStatus, errorThrown) { mk_cate_wish_action_lodding = false; } }); return; } function mk_prd_wish_login(is_mobile) { var login_url = is_mobile == true ? '/m/login.html' :'/shop/member.html'; if (confirm("회원에게만 제공이 되는 서비스입니다.\n우선 로그인을 하여 주시기 바랍니다.")) { document.location.href = login_url; } } function mk_call_fbq(type, id) { if (typeof fbq === 'function') { fbq('track', type, {}, {eventID: id}); } }